package com.ruoyi.ssh.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ssh.domain.QuestionOption;
import com.ruoyi.ssh.service.IQuestionOptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 题目选项Controller
 * 
 * @author ruoyi
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/ssh/questionOption")
public class QuestionOptionController extends BaseController
{
    @Autowired
    private IQuestionOptionService questionOptionService;
    /**
     * 根据id查询题目选项
     *
     * @param id 题目选项主键
     * @return 题目选项
     */
    @PreAuthorize("@ss.hasPermi('ssh:questionOption:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(questionOptionService.selectQuestionOptionById(id));
    }

    /**
     * 根据题目ID查询选项
     *
     * @param questionId 题目ID
     * @return 题目选项
     */
    @PreAuthorize("@ss.hasPermi('ssh:questionOption:query')")
    @GetMapping(value = "/queryByQuestionId/{questionId}")
    public AjaxResult getInfoByQuestionId(@PathVariable("questionId") Integer questionId)
    {
        return AjaxResult.success(questionOptionService.selectQuestionOptionByQuestionId(questionId));
    }

    /**
     * 动态添加选项
     *
     * @param questionOption 题目选项
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('ssh:questionOption:add')")
    @Log(title = "动态添加选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionOption questionOption)
    {
        return toAjax(questionOptionService.insertQuestionOption(questionOption));
    }
    /**
     * 动态修改选项
     *
     * @param questionOption 题目选项
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('ssh:questionOption:edit')")
    @Log(title = "动态修改选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionOption questionOption)
    {
        return toAjax(questionOptionService.updateQuestionOption(questionOption));
    }

    /**
     * 通过题目ID查询选项
     *
     * @param questionId 题目ID
     * @return 题目选项
     */
    @PreAuthorize("@ss.hasPermi('ssh:questionOption:query')")
    @GetMapping(value = "/queryWithQuestion/{questionId}")
    public AjaxResult getInfoWithQuestion(@PathVariable("questionId") Integer questionId)
    {
        return AjaxResult.success(questionOptionService.selectQuestionOptionWithQuestion(questionId));
    }

}
